package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-03-15 21:45
 **/
public class LeetCode2044 {

    //二进制枚举+位运算
    public int countMaxOrSubsets(int[] nums) {
        int n = nums.length;
        int cnt = 0;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < (1 << n); i++) {
            int cur = 0;
            for (int j = 0; j < n; j++) {
                if (((1 << j) & i) != 0) {
                    cur |= nums[j];
                }
            }
            if (cur > max) {
                max = cur;
                cnt = 1;
            } else if (cur == max) {
                ++cnt;
            }
        }
        return cnt;
    }

}
